package craky.componentc;

import java.awt.Graphics;

import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.ScrollPaneUI;
import javax.swing.plaf.basic.BasicScrollPaneUI;

import craky.util.UIUtil;

public class CScrollPaneUI extends BasicScrollPaneUI
{
    private static ScrollPaneUI viewportUI;

    public static ComponentUI createUI(JComponent c)
    {
        if(viewportUI == null)
        {
            viewportUI = new CScrollPaneUI();
        }
        
        return viewportUI;
    }
    
    public void update(Graphics g, JComponent c)
    {
        if(c instanceof JCScrollPane)
        {
            paintBackground(g, c);
        }
        
        super.update(g, c);
    }
    
    private void paintBackground(Graphics g, JComponent c)
    {
        JCScrollPane scrollPane = (JCScrollPane)c;
        UIUtil.paintBackground(g, scrollPane, scrollPane.getBackground(), scrollPane.getBackground(), scrollPane.getImage(),
                        scrollPane.isImageOnly(), scrollPane.getAlpha(), scrollPane.getVisibleInsets());
    }
    
    protected void installDefaults(JScrollPane scrollpane)
    {}
    
    protected void uninstallDefaults(JScrollPane scrollpane)
    {}
}